home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CAnimCursor / CAnimCursor.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  5.1 KB  |  199 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CAnimCursor.h
  3.  * Version 1.0b4, 14 September 1992
  4.  *
  5.  */
  6.  
  7.  
  8.  
  9. /********************************/
  10.  
  11. #pragma once
  12.  
  13. /********************************/
  14.  
  15. #include <oops.h>
  16.  
  17. /********************************/
  18.  
  19. #include <Retrace.h>
  20.  
  21. /********************************/
  22.  
  23. enum {
  24.     kCACModeInterrupted,
  25.     kCACModeContinuous
  26. } ;
  27.  
  28.     /*
  29.      * Go back to the normal cursor each time through the event loop,
  30.      * by default.
  31.      */
  32. #define kCACDefaultMode (kCACModeInterrupted)
  33.  
  34.     /* Do about eight cursors per second, by default. */
  35. #define kCACDefaultTicksBetweenCursors (8)
  36.  
  37.     /* Wait a half-second before beginning, by default. */
  38. #define kCACDefaultInitialDelayTicks (30)
  39.  
  40.     /*
  41.      * Give the "normal" code one tick to sneak in ahead of the interrupt,
  42.      * by default.
  43.      */
  44. #define kCACDefaultColorInterruptSlop (1)
  45.  
  46. /********************************/
  47.  
  48. class CAnimCursor;
  49. extern CAnimCursor *gAnimCursor;
  50.  
  51. /********************************/
  52.  
  53. typedef struct {
  54.     short            nCursors;
  55.     short            cCursor;
  56.     CursHandle    cursor[];
  57. } acurStruct;
  58. typedef acurStruct *acurPtr, **acurHndl;
  59.  
  60. /********************************/
  61.  
  62.  
  63.  
  64. class CAnimCursor : public indirect {
  65.     
  66. public:
  67.     
  68.     void            IAnimCursor(short rsrcID);
  69.     void            Dispose(void);
  70.     
  71.     
  72.                         /*
  73.                          * Be sure to set the resource file appropriately, with
  74.                          * UseResFile(), before you call useAnimCursorID().  Be
  75.                          * aware that IAnimCursor() calls it, too.
  76.                          */
  77.     void            useAnimCursorID(short rsrcID);
  78.     void            stopUsingAnimCursor(void);
  79.     
  80.     
  81.                         /* These two methods start and stop the action. */
  82.     void            startAnimating(void);
  83.     void            stopAnimating(void);
  84.                         /* This one tells you whether the action's going on. */
  85.     Boolean        getIsAnimating(void);
  86.     
  87.     
  88.                         /*
  89.                          * This is called from the interrupt task, as well as by
  90.                          * your code.  You don't have to call it unless you
  91.                          * want color (color can't be used from an interrupt),
  92.                          * or you called setUsingInterrupts(FALSE).
  93.                          */
  94.     void            animateCursor(void);
  95.     
  96.     
  97.                         /* The default tick values are defined above. */
  98.     void            setTicksBetweenCursors(short newTicksBetweenCursors);
  99.     void            setInitialDelayTicks(short newInitialDelayTicks);
  100.     
  101.     
  102.                         /*
  103.                          * By default, it uses interrupts;  if you prefer a
  104.                          * non-smooth animation, or one that will stop when your
  105.                          * code hits an infinite loop, do setUseInterrupts(FALSE)
  106.                          * and call animateCursor() as often as possible.
  107.                          */
  108.     void            setUsingInterrupts(Boolean newUsingInterrupts);
  109.     Boolean        getUsingInterrupts(void);
  110.     
  111.     
  112.                         /*
  113.                          * If you want your color cursor to be used, you've got to
  114.                          * call gAnimCursor->animateCursor() every so often.  But
  115.                          * the interrupt routine will always get to it before you
  116.                          * will, unless you give yourself a few ticks where _you_
  117.                          * can call animateCursor(), but the _interrupt_ can't.
  118.                          * These ticks are called "slop."  (Of course, if you
  119.                          * turn interrupts off, slop doesn't matter.)
  120.                          */
  121.     void            setSlopTicks(short newSlopTicks);
  122.     short            getSlopTicks(void);
  123.     
  124.     
  125.                         /*
  126.                          * By default, animation stops each time through the TCL's
  127.                          * event loop:  CAcurSwitchboard calls stopAnimating(), and
  128.                          * CAcurDesktop lets the CView hierarchy determine what the
  129.                          * cursor should be.  If you don't like this, call
  130.                          * setMode(kCACContinuous), and animation will continue
  131.                          * through the event loop.  Of course, your CView hierarchy
  132.                          * will lose control over what the cursor looks like.
  133.                          * (If you're not using the TCL, the mode doesn't matter.)
  134.                          */
  135.     void            setMode(short newMode);
  136.     short            getMode(void);
  137.     
  138.     
  139.                         /*
  140.                          * To avoid finding 'crsr' resources in the System file or
  141.                          * somesuch, CAnimCursor grabs the refNum of the top
  142.                          * resource file when IAnimCursor is found, and assumes
  143.                          * all the 'crsr' resources are in that file.
  144.                          */
  145.     void            setTopResFile(short newTopResFile);
  146.     void            useTopResFile(void);
  147.     
  148.     
  149.                         /*
  150.                          * If TRUE, the interrupt handler is running.  This must
  151.                          * be public, because the (non-method) callback routine
  152.                          * must access it;  but you shouldn't mess with it.
  153.                          */
  154.     Boolean        isInAnInterrupt;
  155.     
  156.     
  157. protected:
  158.     
  159.     Boolean            isAnimating;
  160.     Boolean            tryToUseColor;
  161.     Boolean            usingColorCursors;
  162.     Boolean            usingInterrupts;
  163.     Boolean            vblTaskIsInstalled;
  164.     Boolean            isInAnimateCursor;        // if TRUE, the interrupt will not re-enter
  165.     
  166.     short                itsTopResFile;
  167.     short                itsAcurID;
  168.     acurHndl            itsAcurHndl;
  169.     
  170.     short                itsTicksBetweenCursors;
  171.     short                itsTicksBetweenCursorsForInterrupt;
  172.     short                itsTicksBetweenCursorsForNormalCode;
  173.     short                itsInitialDelayTicks;
  174.     unsigned long    itsInitialTick;
  175.     unsigned long    itsLastTick;
  176.     
  177.     short                itsMode;
  178.     
  179.                             /**********
  180.                              * Note that these two variables _must_ be declared
  181.                              * right next to each other, in this order. */
  182.     long                itsA5;
  183.     VBLTask            itsVBLTask;
  184.                             /* If they aren't, the VBL task will choke and die
  185.                              * when it tries to get at global variables.
  186.                              **********/
  187.     
  188.     
  189.     void            determineTryToUseColor(void);
  190.     
  191.     void            loadIndividualCursors(void);
  192.     void            disposeIndividualCursors(void);
  193.     
  194.     OSErr            installVBLTask(void);
  195.     OSErr            removeVBLTask(void);
  196.     
  197.     void            nextCursor(void);
  198.     
  199. } ;